Skip to content

Manchester | 26-ITP-Jan | Farancis Dore Etonkie | Sprint 3 | Module Structuring and testing data#1216

Open
FarancisGH wants to merge 2 commits intoCodeYourFuture:mainfrom
FarancisGH:coursework/sprint-3-implement-and-rewrite
Open

Manchester | 26-ITP-Jan | Farancis Dore Etonkie | Sprint 3 | Module Structuring and testing data#1216
FarancisGH wants to merge 2 commits intoCodeYourFuture:mainfrom
FarancisGH:coursework/sprint-3-implement-and-rewrite

Conversation

@FarancisGH
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  1. Exercises done on fractions, angles, and values

…ction. Added an example test case for right angles and a comment to indicate where to write additional tests. Also added explanations for the implementation of the isProperFraction function and the multiply function in the previous sprint.
@FarancisGH FarancisGH added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Structuring-And-Testing-Data The name of the module. labels Mar 7, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Function implementation is correct.

  • Tests and test description could use some improvement.


function isProperFraction(numerator, denominator) {
// TODO: Implement this function
// A proper fraction is a fraction where the absolute value of the numerator is less than the absolute value of the denominator. Additionally, the denominator cannot be zero. Therefore, we can check if the absolute value of the numerator is less than the absolute value of the denominator and if the denominator is not zero to determine if it is a proper fraction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to break a long comment into multiple lines so that we don't need to scroll horizontally in an editor to view all the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests in this script do not yet cover all cases.

Comment on lines +6 to +25
// Example: 1/2 is a proper fraction
test(`should return true for 1/2`, () => {
expect(isProperFraction(1, 2)).toEqual(true);
});
// Example: 2/1 is not a proper fraction
test(`should return false for 2/1`, () => {
expect(isProperFraction(2, 1)).toEqual(false);
});
// Example: -1/2 is a proper fraction
test(`should return true for -1/2`, () => {
expect(isProperFraction(-1, 2)).toEqual(true);
});
// Example: 1/-2 is a proper fraction
test(`should return true for 1/-2`, () => {
expect(isProperFraction(1, -2)).toEqual(true);
});
// Example: -1/-2 is a proper fraction
test(`should return true for -1/-2`, () => {
expect(isProperFraction(-1, -2)).toEqual(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good that the selected test values cover all combinations of positive and negative values.

To make the tests clearer that all fractions that satisfy abs(numerator) < abs(denominator) are proper fractions, we could also express the test as:

test("should return true when abs(numerator) < abs(denominator)", () => {
  expect(isProperFraction(1, 2)).toEqual(true);
  expect(isProperFraction(-1, 2)).toEqual(true);
  expect(isProperFraction(1, -2)).toEqual(true);
  expect(isProperFraction(-1, -2)).toEqual(true);
});

Comment on lines +15 to +25
test(`should return 10 for "J♦"`, () => {
expect(getCardValue("J♦")).toEqual(10);
});

test(`should return 10 for "Q♣"`, () => {
expect(getCardValue("Q♣")).toEqual(10);
});

test(`should return 10 for "K♠"`, () => {
expect(getCardValue("K♠")).toEqual(10);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples.

For example, one possible category for getCardValue() is, "should return 10 for face cards", and we can prepare the test as

test("should return 10 for face cards (J, Q, K)", () => {
    expect(getCardValue("J♣︎")).toEqual(10);
    expect(getCardValue("Q♠")).toEqual(10);
    expect(getCardValue("K♥")).toEqual(10);
});

Can you practice preparing tests in this fashion?

Comment on lines 36 to 41
// Invalid Cards


// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also implement this test? (Invalid case)

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Structuring-And-Testing-Data The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants